package com.shrw.duke.bluetoothheartrate.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.shrw.duke.bluetoothheartrate.R;
import com.shrw.duke.bluetoothheartrate.entity.RateEntity;
import com.shrw.duke.bluetoothheartrate.entity.StateEntity;

import java.text.DecimalFormat;

public class RateDataActivity extends AppCompatActivity {


    private RateEntity mRateEntity = null;

    private TextView mTvName,mTvAddress,mTvRate,mTvVoltage,mTvActCount,
            mTvSendCount,mTvAct1,mTvRssi1,mTvAct2,mTvRssi2,mTvAct3,mTvMeasoreTime;
    private TextView mTvAtcZone,mTvTamper,mTvBottom,mTvShake,mTvReceiveState,mTvElectricitySign;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_data);

        Bundle bundle = getIntent().getExtras();
        mRateEntity = (RateEntity)bundle.getParcelable(RateActivity.LABEL_DATA);

        initView();
    }

    private void initView() {
        mTvName = (TextView) findViewById(R.id.tv_name);
        mTvAddress = (TextView) findViewById(R.id.tv_address);
        mTvRate = (TextView) findViewById(R.id.tv_rate);
        mTvVoltage = (TextView) findViewById(R.id.tv_voltage);
        mTvActCount = (TextView) findViewById(R.id.tv_act_count);
        mTvSendCount = (TextView) findViewById(R.id.tv_send_count);
        mTvAct1 = (TextView) findViewById(R.id.tv_act1);
        mTvRssi1 = (TextView) findViewById(R.id.tv_act_rssi_1);
        mTvAct2 = (TextView) findViewById(R.id.tv_act2);
        mTvRssi2 = (TextView) findViewById(R.id.tv_act_rssi_2);
        mTvAct3 = (TextView) findViewById(R.id.tv_act3);
        mTvMeasoreTime = (TextView) findViewById(R.id.tv_measure_time);

//        status
        mTvAtcZone = (TextView) findViewById(R.id.tv_atc_zone);
        mTvTamper = (TextView) findViewById(R.id.tv_tamper);
        mTvBottom = (TextView) findViewById(R.id.tv_bottom);
        mTvShake = (TextView) findViewById(R.id.tv_shake);
        mTvReceiveState = (TextView) findViewById(R.id.tv_receive_state);
        mTvElectricitySign = (TextView) findViewById(R.id.tv_electricity_sign);
        if (mRateEntity!=null){
            mTvName.setText(mRateEntity.getName());
            mTvAddress.setText(mRateEntity.getAddress());
            mTvRate.setText(Integer.parseInt(mRateEntity.getRate(),16)+"");
            DecimalFormat format = new DecimalFormat("#.0");
            mTvVoltage.setText(format.format((Integer.parseInt(mRateEntity.getVolt(),16))/10));
            mTvActCount.setText(Integer.parseInt(mRateEntity.getLf_Times(),16)+"");
            mTvSendCount.setText(Integer.parseInt(mRateEntity.getNrf_Times(),16)+"");
//            mTvAct1.setText(Integer.parseInt(mRateEntity.getAID_STR1_ActID(),16)+"");
            mTvAct1.setText(mRateEntity.getAID_STR1_ActID());
            mTvRssi1.setText(Integer.parseInt(mRateEntity.getAID_STR1_Rssi(),16)+"");
            mTvAct2.setText(Integer.parseInt(mRateEntity.getAID_STR2_ActID(),16)+"");
            mTvRssi2.setText(Integer.parseInt(mRateEntity.getAID_STR2_Rssi(),16)+"");
            mTvAct3.setText(Integer.parseInt(mRateEntity.getAID_STR3_ActID(),16)+"");
            StateEntity state = mRateEntity.getStateEntity();
            mTvAtcZone.setText("0".equals(state.getActive_region()) ? "不在激活区" : "在激活区");
            mTvTamper.setText("0".equals(state.getAnti_dismantle())? "正常":"异常");
            mTvBottom.setText("0".equals(state.getButton())? "按下":"无");
            mTvShake.setText("0".equals(state.getVibrating_sensor())? "无":"震动");
            mTvReceiveState.setText("0".equals(state.getOpen_receive())? "关闭":"打开");
            mTvElectricitySign.setText("0".equals(state.getElectricity_sign())? "正常":"上电");
            mTvMeasoreTime.setText(mRateEntity.getMeasoreTime());
        }
    }
}
